package cn.itcast.shop.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import cn.itcast.shop.adminuser.AdminUser;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class LoginInterceptor extends MethodFilterInterceptor {

	@Override
	protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
		AdminUser adminUser=(AdminUser) ServletActionContext.getRequest().getSession().getAttribute("existAdminUser");
		if(adminUser !=null){
		
			return actionInvocation.invoke();
		}else{
			ActionSupport action=(ActionSupport) actionInvocation.getAction();
			action.addActionError("你还没登陆!");
			/*HttpServletResponse response=ServletActionContext.getResponse();
			HttpServletRequest request= ServletActionContext.getRequest();
			response.sendRedirect(request.getContextPath()+"/admin/index.jsp");*/
			return action.LOGIN;
		}
		
	}

}
